﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace StuApart
{
    public partial class StudentCheck : Form
    {
        string connStr = Properties.Settings.Default.StuApartConnectionString;
        SqlConnection conn;
        SqlDataAdapter adapter;
        DataTable table = new DataTable();


        public StudentCheck()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“stuApartDataSet1.Student”中。您可以根据需要移动或移除它。
            this.studentTableAdapter.Fill(this.stuApartDataSet1.Student);

            conn = new SqlConnection(connStr);
            adapter = new SqlDataAdapter("SELECT * FROM student", conn);
            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
            adapter.InsertCommand = builder.GetInsertCommand();
            adapter.UpdateCommand = builder.GetUpdateCommand();
            adapter.DeleteCommand = builder.GetDeleteCommand();
            adapter.Fill(table);
            studentBindingSource.DataSource = table;
            // TODO: 这行代码将数据加载到表“stuApartDataSet.StudentIn”中。您可以根据需要移动或移除它。
            this.studentTableAdapter.Fill(this.stuApartDataSet1.Student);

        }


        private void fillByToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.studentTableAdapter.Fill(this.stuApartDataSet1.Student);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void DisplayMessage()
        {



        }
        private void button1_Click(object sender, EventArgs e)
        {

            if (textBox1.Text == "" && textBox2.Text == "")
            {
                MessageBox.Show("姓名和学号不能为空!");
            }
            string conditionStr = "";
            if (textBox1.Text.Trim() != "")
            {
                if (conditionStr == "")
                    conditionStr = "Name LIKE'" + textBox1.Text.Trim() + "%'";
                else
                    conditionStr += "AND Name LIKE'" + textBox1.Text.Trim() + "%'";
            }
            if (textBox2.Text.Trim() != "")
                conditionStr = "No LIKE'" + textBox2.Text.Trim() + "%'";
            studentBindingSource.Filter = conditionStr;

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void studentBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.studentBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.stuApartDataSet1);

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();

        }
    }
}
